<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<jsp:include page="frame/header.jsp"></jsp:include>

<title>常用信息指南</title>

<style>
.pagination .active a {
	/*background-color: #CC0041;
	color:white;*/
}
</style>

</head>

<body>

	<div class="container-fluid">
		<div id="market" class="row-fluid">
			<div>
				<ul class="breadcrumb">
					<li><a href="#">生活信息</a> <span class="divider">/</span></li>
					<li><a href="#">常用信息指南</a></li>
				</ul>
			</div>

			<div class="box">
				<div class="box-header well" data-original-title>
					<h2>
						<i class="icon-th"></i> 常用信息列表
					</h2>

					<div class="box-icon">
						<a href="#" class="btn btn-setting btn-round"><i
							class="icon-cog"></i></a> <a href="#"
							class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						<a href="#" class="btn btn-close btn-round"><i
							class="icon-remove"></i></a>
					</div>
				</div>
				<div class="box-content">
					<div id="search-form">
						<form class="form-search span12">
							<select id="liveSorts" class="input-xlarge" name="liveSorts" >
									<option value="0">全部</option>
									<c:forEach var="sort" items="${sorts }">
										<option value="${sort.sortId }">${sort.sortName }</option>
									</c:forEach>
							</select>
							<input type="text" id="searchText" value="${search }" 
								class="input-xlarge search-query">
							<button type="button" id="searchBtn" class="btn">&nbsp;&nbsp;搜索&nbsp;&nbsp;</button>
							<button type="button" id="newBtn" class="btn btn-danger pull-right">添加常用信息</button>
						</form>

					</div>
					<table id="userInfo" class="table table-striped table-bordered ">
						<thead>
							<tr>
								<th width="30">序号</th>
								<th width="80">分类</th>
								<th>名称</th>
								<th>电话</th>
								<th width="50">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach var="info" items="${pageModel.result }" varStatus="status">
								<tr>
									<td>${status.index+1 }</td>
									<td>${info.sortName }</td>
									<td>${info.name } </td>
									<td>${info.phone }</td>
									<td><a href="javascript:edit('${info.infoId }')"><i
											class="icon-edit"></i></a> &nbsp;&nbsp; <a
										href="javascript:del('${info.infoId }')"><i class="icon-minus"></i></a></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					
					<div id="mypager" class="mypager"></div>
				</div>
			</div>
		</div>
		<!--/fluid-row-->

	</div>
	<!--/.fluid-container-->

	<jsp:include page="frame/scripts.jsp"></jsp:include>
	<script type="text/javascript">
	
	var pageNum = "${pageModel.pageNum}";
	var totalPage = "${pageModel.totalPage}";
	var numPerPage = "${pageModel.numPerPage}";
	
	$(document).ready(function(){
		
		$("#newBtn").click(function(){
			//跳转至新增页面
			window.location.href = '<c:url value="/admin/addCommon" />';
		})
		
		$('#mypager').bootstrapPaginator({
			currentPage:pageNum,
			totalPages:totalPage,
			numberOfPages:numPerPage,
			onPageClicked:function(event, originalEvent, type,page){
				getPagedUrl($("#liveSorts").val(),page);
			}
		});
		
		$('#liveSorts').val(${sortId});
		
		$('#liveSorts').change(function(){
			getPagedUrl($(this).val(),1);
		})
		
		$('#searchBtn').click(function(){
			getPagedUrl($("#liveSorts").val(),1);
		})
	})
	
	function getPagedUrl(sortId,pageNum){
		var search = $('#searchText').val();
		window.location.href = '<c:url value="/admin/live_common?pageNum='+pageNum+'&sortId='+sortId+'&search='+search+'"/>';
	}
	function edit(infoId){
		window.location.href = '<c:url value="/admin/editCommon?infoId='+infoId+'"/>';
	}
	function del(infoId){
		var sortId = $("#liveSorts").val();
		if(confirm("确定要删除吗？")){
			window.location.href = '<c:url value="/admin/delCommon?pageNum='+pageNum+'&sortId='+sortId+'&infoId='+infoId+'"/>';	
		}
	}
	</script>
</body>
</html>
